/**
 * Copyright (C) 2013 SHANGHAI VOLKSWAGEN, All rights reserved.
 * License version 1.0, a copy of which has been included with this.
 *
 * @File name：com.bwie.community.websocket.SemaphoreUtils
 * @Create on：2024/4/5
 * @Author：liuchang
 */
package com.bwie.community.websocket;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.Semaphore;

/**
 * <p>ClassName：SemaphoreUtils</p >
 * <p>Description：</p >
 * <p>Author：liuchang</p >
 * <p>Date：2024/4/5</p >
 */
public class SemaphoreUtils {
    /*
    * 日志控制器
    * */
    private static final Logger LOGGER= LoggerFactory.getLogger(SemaphoreUtils.class);

    /*
    * 获取信号量
    *
    * */
   public static boolean tryAcquire(Semaphore semaphore){
          boolean flag=false;

       try {
           flag= semaphore.tryAcquire();
       } catch (Exception e) {
          LOGGER.info("获取信号量异常",e);
       }
        return flag;
   }
   /*
   *释放信号量
   * */
    public static void release(Semaphore semaphore){
        try {
            semaphore.release();
        } catch (Exception e) {
            LOGGER.error("信号量释放异常",e);
        }
    }
}
